<template>
  <view class="page">
    <Header :title="'抗遗忘复习'"></Header>
    <view class="main_container">
      <view class="main_content">
        <view class="content">
          <view class="tabs">
            <reviewTabs :current="0"></reviewTabs>
          </view>
          <view class="box">
            <LianLianKanNew
              v-if="wordList.length > 0"
              ref="lianliankan"
              :wordList="wordList"
              @complete="completeRecord"
              @save="saveRecord"
              @end="back"
            ></LianLianKanNew>
          </view>
        </view>
      </view>
    </view>
    <u-count-down
      class="countdown"
      ref="uCountDown"
      :timestamp="timestamp"
    ></u-count-down>
  </view>
</template>

<script>
import { getWords, saveWordLearningRecord, kyw21dk } from "@/api/sync";
import reviewTabs from "./reviewTabs";

export default {
  components: { reviewTabs },
  data() {
    return {
      chapterId: "",
      fxId: "",
      wordList: [],
      timestamp: 86400,
    };
  },
  onLoad(options) {
    this.chapterId = options.chapterId;
    this.fxId = options.fxId;
    this.getData();
  },
  methods: {
    getData() {
      getWords("kyw21", this.chapterId).then((res) => {
        this.wordList = res.data;
      });
    },
    saveRecord(isPass, id) {
      let params = {
        pass: isPass ? 1 : 0,
        step: "8",
        type: "kyw21",
        wordId: id,
        batch: this.fxId,
      };
      saveWordLearningRecord(params);
    },
    completeRecord() {
      let params = {
        errIds: "",
        wrongCount: 0,
        fxCount: this.wordList.length,
        fxId: this.fxId,
        step: "8",
        timeDur: this.timestamp - this.$refs.uCountDown.seconds,
      };
      kyw21dk(params);
    },
    back() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./review1LianLianKan";
</style>
